package com.gxr.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.dao.ObjectDao;
import com.pro.bean.Unit;

import util.StrConvert;

public class GetUserServlet extends HttpServlet {

	/**
	 * ����û����� ��ȡ�û���Ϣ��ת���û���Ϣ���棨ֻ����
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		request.setCharacterEncoding("UTF-8");
		
		String userid=(String)request.getParameter("userId");
		System.out.println("getUserServlet"+userid);
		String username=StrConvert.ToCN(request.getParameter("username"));
		System.out.println("getUserServlet"+username);
		String useremail=(String)request.getParameter("useremail");
		String userunit=(String)request.getParameter("userunit");
		String unitid=(String)request.getParameter("unitId");
		
		HttpSession session=request.getSession();
		session.setAttribute("userid", userid);
		session.setAttribute("username",username);
	
		session.setAttribute("email", useremail);
		session.setAttribute("company", userunit);
		
		Unit unit =new Unit();
		ObjectDao ObjectDao=new ObjectDao();
		List lUnit=ObjectDao.findall(unit);
		HttpSession sessionUnit=request.getSession();
		sessionUnit.setAttribute("list", lUnit);

		RequestDispatcher dispatcher=request.getRequestDispatcher("../gxr/admin_userinfo.jsp");
		dispatcher.forward(request, response);
	}

	/**
	 * 
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
/*
		//int userId=Integer.getInteger(request.getParameter("userId"));
		String username=request.getParameter("username");
		String email=request.getParameter("email");
		//response.setContentType("text/html",charset="gb2312");
		//String company=request.getParameter("company");
		//PrintWriter out = response.getWriter();
		//out.println(username);
		//out.println(company);
		HttpSession session=request.getSession();
		//session.setAttribute("userId", userId);
		session.setAttribute("username", username);
		session.setAttribute("email", email);
		//session.setAttribute("company", company);
*/
		RequestDispatcher dispatcher=request.getRequestDispatcher("../gxr/admin_userinfo.jsp");
		dispatcher.forward(request, response);
	}

}
